
package com.joysuch.wwyt.bp.enums;

public enum UserTypes {

    STAFF("IN", "内部"), CONTRACTOR("OUT", "承包商");

    private String code;
    private String name;

    private UserTypes(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static UserTypes findByName(String name) {
        UserTypes[] values = UserTypes.values();
        for (UserTypes v : values) {
            if (v.getName().equals(name)) {
                return v;
            }
        }
        return null;
    }

    public static UserTypes findByCode(String code) {
        UserTypes[] values = UserTypes.values();
        for (UserTypes v : values) {
            if (v.getCode().equals(code)) {
                return v;
            }
        }
        return null;
    }

    public static String findNameByCode(String code) {
        UserTypes types = findByCode(code);
        return types == null ? null : types.name;
    }
}
